package com.kupurui.asteacher.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.frame.adapter.CommonAdapter;
import com.android.frame.adapter.ViewHolder;
import com.android.frame.view.linearlistview.LinearListView;
import com.kupurui.asteacher.R;
import com.kupurui.asteacher.bean.JobInfo;
import com.kupurui.asteacher.bean.NewJobInfo;
import com.kupurui.asteacher.ui.job.AllJobAty;
import com.kupurui.asteacher.ui.job.JobOverviewAty;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/7/21.
 */

public class JobAdapter extends CommonAdapter<NewJobInfo.FabuBean> {
    JobChildAdapter adapter;

    public JobAdapter(Context context, List<NewJobInfo.FabuBean> mList, int itemLayoutId) {
        super(context, mList, itemLayoutId);
    }

    @Override
    public void convert(ViewHolder holder, final NewJobInfo.FabuBean item, int positon) {
        LinearListView listView = holder.getView(R.id.listview);
        adapter = new JobChildAdapter(mContext,item.getHomework(),R.layout.job_child_item);
        listView.setAdapter(adapter);

        holder.setTextViewText(R.id.tv_school_name,"学校："+item.getSchool());
        holder.setTextViewText(R.id.tv_grade,"年级："+item.getGrade());
        holder.setTextViewText(R.id.tv_class_name,"班级："+item.getName());
        holder.setTextViewText(R.id.tv_student_num,"班级人数："+item.getNum()+"人");
        holder.setTextViewText(R.id.tv_tijiaolv,item.getTijiaolv()+"%");
        holder.setTextViewText(R.id.tv_online,item.getOnline()+"%");
        holder.setTextViewText(R.id.tv_zhengquelv,item.getZhengquelv()+"%");

        listView.setOnItemClickListener(new LinearListView.OnItemClickListener() {
            @Override
            public void onItemClick(LinearListView parent, View view, int position, long id) {
                Bundle bundle = new Bundle();
                bundle.putString("id",item.getHomework().get(position).getId());
                bundle.putString("class_id",item.getId());
                Intent intent = new Intent();
                intent.setClass(mContext,JobOverviewAty.class);
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });

        LinearLayout llAllJob = holder.getView(R.id.ll_all_job);
        llAllJob.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("id",item.getId());
                Intent intent = new Intent();
                intent.setClass(mContext, AllJobAty.class);
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });
    }
}
